<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Thông tin shop</title>
		<link rel="stylesheet" href="../css/reset.css" type="text/css" />
		<link rel="stylesheet" href="../css/common.css" type="text/css" />
		<link rel="stylesheet" href="../css/seller.css" type="text/css" />
        <link rel="stylesheet" href="../css/MenuMatic2.css" type="text/css" />
		<script src="../scripts/jquery-1.5.2.min.js"></script>
		<script src="../scripts/common.js"></script>
		<script type="text/javascript">
			$(document).ready(function(){
				$('ul#nested-list li.open > ul').hide();
				$('ul#nested-list li.open > span').addClass('closed');
				
				$('ul#nested-list li.open > span').click(function(){
					if ($(this).hasClass('closed')) {						
						$(this).parent().find('> ul').show('slow');						
						$(this).css('background', 'url("../images/minus-bullet.jpg") no-repeat 0px 6px');
						$(this).removeClass('closed');
						$(this).addClass('opened');
						return;
					}
					
					if ($(this).hasClass('opened')) {
						
						$(this).parent().find('> ul').hide('slow');						
						$(this).css('background', 'url("../images/plus-bullet.jpg") no-repeat 0px 6px');
						$(this).removeClass('opened');
						$(this).addClass('closed');
						return;
					}
				});
			});
			
			var xmlhttp;
	
			function GetXmlHttpObject()
			{
				if (window.XMLHttpRequest)
				{
					// code for IE7+, Firefox, Chrome, Opera, Safari
					return new XMLHttpRequest();
				}
				if (window.ActiveXObject)
				{
					// code for IE6, IE5
					return new ActiveXObject("Microsoft.XMLHTTP");
				}
				return null;
			}
			var IDDanhMuc;
			function Sua(Id)
			{
				xmlhttp = GetXmlHttpObject();
				if(xmlhttp == null)
				{
					alert("Browser do not support HTTP REQUEST");
					return;
				}
				IDDanhMuc = Id;
				var serverURL = "../BUS/xl_DanhMuc.php?MaDM=" + Id + "&Sua=1";
				xmlhttp.onreadystatechange=Sua_Change;
				xmlhttp.open("GET",serverURL,true);
				xmlhttp.send("null");
				
			}
			
			function Sua_Change()
			{
				
				if (xmlhttp.readyState==4)
				{
					var node = document.getElementById(IDDanhMuc);
					node.innerHTML=xmlhttp.responseText;
					
					node.parentNode.removeChild(document.getElementById("add".concat(IDDanhMuc)));
					node.parentNode.removeChild(document.getElementById("delete".concat(IDDanhMuc)));
					node.parentNode.removeChild(document.getElementById("edit".concat(IDDanhMuc)));				
					
					var node1 = document.createElement("input");
					node1.setAttribute("type","button");
					node1.setAttribute("class", "ok");
					var str = "ok"
					var str2 = str.concat(IDDanhMuc);
					node1.setAttribute("id", str2);
					var str = "CapNhat("
					var str2 = str.concat(IDDanhMuc,")");
					node1.setAttribute("onclick", str2);
					
					var node2 = document.createElement("input");
					node2.setAttribute("type","button");
					node2.setAttribute("class", "cancel");
					var str = "HuyCapNhat("
					var str2 = str.concat(IDDanhMuc,")");
					node2.setAttribute("onclick", str2);
					var str = "cancel"
					var str2 = str.concat(IDDanhMuc);
					node2.setAttribute("id", str2);
					
					node.parentNode.insertBefore(node2,node.nextSibling);
					node.parentNode.insertBefore(node1,node.nextSibling);
					
				}
			}
			
			function Xoa(Id)
			{
				xmlhttp = GetXmlHttpObject();
				if(xmlhttp == null)
				{
					alert("Browser do not support HTTP REQUEST");
					return;
				}
				if(confirm("Xác nhận xóa danh mục ?"))
				{
					IDDanhMuc = Id;
					var serverURL = "../BUS/xl_DanhMuc.php?MaDM=" + Id + "&Xoa=1";
					xmlhttp.onreadystatechange=Xoa_Change;
					xmlhttp.open("GET",serverURL,true);
					xmlhttp.send("null");
				}
				
			}
			
			function Xoa_Change()
			{
				
				if (xmlhttp.readyState==4)
				{
					var node = document.getElementById(IDDanhMuc);
					node.innerHTML=xmlhttp.responseText;
					if(document.getElementById("infor").value == 0)
					{
						node.parentNode.parentNode.removeChild(node.parentNode);
						alert("Xóa danh mục thành công");
					}
					else
					{
						alert("Danh mục này có chứa danh mục con hoặc sản phẩm rồi, vui lòng kiểm tra lại!");
						node.removeChild(document.getElementById("infor"));
					}
				}
			}
			
			function Add(Id)
			{
				IDDanhMuc = Id;
				var root = document.getElementById(IDDanhMuc);
				var temp;
				
				if($('#' + IDDanhMuc).parent().children('ul').size() > 0)
					temp  = root.parentNode.getElementsByTagName("ul")[0];
				else
					temp = document.createElement("ul");
				var node = document.createElement("li");
				var str = "liadd";
				var str2 = str.concat(IDDanhMuc);
				node.setAttribute("id", str2);
				
				var node1 = document.createElement("input");
				node1.setAttribute("type","text");
				var str = "tbthemtendm"
				var str2 = str.concat(IDDanhMuc,"");
				node1.setAttribute("id", str2);
				
				var node2 = document.createElement("input");
				node2.setAttribute("type","button");
				node2.setAttribute("class", "ok");
				var str = "okadd"
				var str2 = str.concat(IDDanhMuc);
				node2.setAttribute("id", str2);
				var str = "ThemDM("
				var str2 = str.concat(IDDanhMuc,")");
				node2.setAttribute("onclick", str2);
				
				var node3 = document.createElement("input");
				node3.setAttribute("type","button");
				node3.setAttribute("class", "cancel");
				var str = "HuyThemDM("
				var str2 = str.concat(IDDanhMuc,")");
				node3.setAttribute("onclick", str2);
				var str = "canceladd"
				var str2 = str.concat(IDDanhMuc);
				node3.setAttribute("id", str2);
				
				
				node.appendChild(node1);
				node.appendChild(node2);
				node.appendChild(node3);
				temp.appendChild(node);
				root.parentNode.appendChild(temp);
				root.parentNode.removeChild(document.getElementById("add".concat(IDDanhMuc)));
			}
			
			function ThemDM(Id)
			{
				xmlhttp = GetXmlHttpObject();
				if(xmlhttp == null)
				{
					alert("Browser do not support HTTP REQUEST");
					return;
				}
				if(confirm("Bạn có muốn thêm danh mục này không ?"))
				{
					IDDanhMuc = Id;
					var serverURL = "../BUS/xl_DanhMuc.php?TenDM=" + document.getElementById("tbthemtendm".concat(Id)).value + "&ThemDM=1" + "&MaDMCha=" + Id;
					xmlhttp.onreadystatechange=ThemDM_Change;
					xmlhttp.open("GET",serverURL,true);
					xmlhttp.send("null");
				}
				
			}
			
			function ThemDM_Change()
			{
				
				if (xmlhttp.readyState==4)
				{
					var node = document.getElementById("liadd".concat(IDDanhMuc));
					node.innerHTML=xmlhttp.responseText;
					
					var node1 = document.createElement("input");
					node1.setAttribute("type","button");
					node1.setAttribute("class", "add");
					var str = "add"
					var str2 = str.concat(IDDanhMuc);
					node1.setAttribute("id", str2);
					var str = "Add("
					var str2 = str.concat(IDDanhMuc,")");
					node1.setAttribute("onclick", str2);
					
					
					var ma = document.getElementById("insert").value;
					node.removeChild(document.getElementById("insert"));
					
					node.parentNode.parentNode.setAttribute("class","open");
					document.getElementById(IDDanhMuc).setAttribute("class","closed");
					$('span#' + ma).live("click",function()
					{
						if ($(this).hasClass('closed')) {
							$(this).parent().find('> ul').show('slow');						
							$(this).css('background', 'url("../images/minus-bullet.jpg") no-repeat 0px 6px');
							$(this).removeClass('closed');
							$(this).addClass('opened');
							return;
						}
						
						if ($(this).hasClass('opened')) {
							$(this).parent().find('> ul').hide('slow');						
							$(this).css('background', 'url("../images/plus-bullet.jpg") no-repeat 0px 6px');
							$(this).removeClass('opened');
							$(this).addClass('closed');
							return;
						}
					});
					node.removeAttribute("id");
					node.parentNode.parentNode.insertBefore(node1,document.getElementById("edit".concat(IDDanhMuc)));
					
				}
			}
			
			function HuyThemDM(Id)
			{
				IDDanhMuc = Id;
				var node = document.getElementById("canceladd".concat(IDDanhMuc));
				var root = node.parentNode.parentNode.parentNode;
				
				
				var node1 = document.createElement("input");
				node1.setAttribute("type","button");
				node1.setAttribute("class", "add");
				var str = "add"
				var str2 = str.concat(IDDanhMuc);
				node1.setAttribute("id", str2);
				var str = "Add("
				var str2 = str.concat(IDDanhMuc,")");
				node1.setAttribute("onclick", str2);
				
				root.removeChild(node.parentNode.parentNode);
				root.insertBefore(node1,document.getElementById("edit".concat(IDDanhMuc)));
			}
			
			function CapNhat(Id)
			{
				xmlhttp = GetXmlHttpObject();
				if(xmlhttp == null)
				{
					alert("Browser do not support HTTP REQUEST");
					return;
				}
				if(confirm("Bạn có muốn cập nhật không ?"))
				{
					IDDanhMuc = Id;
					var serverURL = "../BUS/xl_DanhMuc.php?MaDM=" + Id + "&TenDM=" + document.getElementById("tbtendm".concat(IDDanhMuc)).value + "&CapNhat=1";
					xmlhttp.onreadystatechange=HuyCapNhat_Change;
					xmlhttp.open("GET",serverURL,true);
					xmlhttp.send("null");
				}
			}
			
			function HuyCapNhat(Id)
			{
				xmlhttp = GetXmlHttpObject();
				if(xmlhttp == null)
				{
					alert("Browser do not support HTTP REQUEST");
					return;
				}
				if(confirm("Bạn không muốn cập nhật nữa"))
				{
					IDDanhMuc = Id;
					var serverURL = "../BUS/xl_DanhMuc.php?MaDM=" + Id + "&HuyCapNhat=1";
					xmlhttp.onreadystatechange=HuyCapNhat_Change;
					xmlhttp.open("GET",serverURL,true);
					xmlhttp.send("null");
				}
			}
			
			function HuyCapNhat_Change()
			{
				
				if (xmlhttp.readyState==4)
				{
					var node = document.getElementById(IDDanhMuc);
					node.innerHTML=xmlhttp.responseText;
					
					node.parentNode.removeChild(document.getElementById("ok".concat(IDDanhMuc)));
					node.parentNode.removeChild(document.getElementById("cancel".concat(IDDanhMuc)));
								
					var node1 = document.createElement("input");
					node1.setAttribute("type","button");
					node1.setAttribute("class", "add");
					var str = "add"
					var str2 = str.concat(IDDanhMuc);
					node1.setAttribute("id", str2);
					var str = "Add("
					var str2 = str.concat(IDDanhMuc,")");
					node1.setAttribute("onclick", str2);
					
					var node2 = document.createElement("input");
					node2.setAttribute("type","button");
					node2.setAttribute("class", "edit");
					var str = "edit"
					var str2 = str.concat(IDDanhMuc);
					node2.setAttribute("id", str2);
					var str = "Sua("
					var str2 = str.concat(IDDanhMuc,")");
					node2.setAttribute("onclick", str2);
					
					var node3 = document.createElement("input");
					node3.setAttribute("type","button");
					node3.setAttribute("class", "delete");
					var str = "delete"
					var str2 = str.concat(IDDanhMuc);
					node3.setAttribute("id", str2);
					var str = "Xoa("
					var str2 = str.concat(IDDanhMuc,")");
					node3.setAttribute("onclick", str2);
					
					node.parentNode.insertBefore(node3,node.nextSibling);
					node.parentNode.insertBefore(node2,node.nextSibling);
					node.parentNode.insertBefore(node1,node.nextSibling);
					
				}
			}
			
		</script>
		<style type="text/css">			
			ul#nested-list span {
				padding-left: 12px;	
				line-height: 25px;
				font-weight: bold;
				color: #0A246A;
			}
			
			ul#nested-list li.open > span {
				background: url("../images/plus-bullet.jpg") no-repeat 0px 6px;
				padding-left: 12px;
				cursor: pointer;
			}
			
			ul#nested-list li {
				padding-left: 20px;
			}
			
			ul#nested-list input.add {
				background: url("../images/add-icon.png") no-repeat;
				width :12px;
				height: 12px;
				border: none;
				cursor: pointer;
				margin-left: 5px;
			}
			
			ul#nested-list input.edit {
				background: url("../images/edit-icon.png") no-repeat;
				border: none;
				width :12px;
				height: 12px;
				cursor: pointer;
			}
			
			ul#nested-list input.delete {
				background: url("../images/delete-icon.png") no-repeat;
				border: none;
				width :12px;
				height: 12px;
				cursor: pointer;
			}
			
			ul#nested-list input.ok {
				background: url("../images/ok-icon.png") no-repeat;
				border: none;
				width :12px;
				height: 12px;
				cursor: pointer;
				margin-left: 5px;
			}
			
			ul#nested-list input.cancel {
				background: url("../images/cancel-icon.png") no-repeat;
				border: none;
				width :12px;
				height: 12px;
				cursor: pointer;
			}
		</style>
	</head>
	<body>
		<div id="page">
			<?php
				require("../DAO/DataHelper.php");
				require("../webconfig.php");
				
				include_once("../DAO/DanhMucSanPham_DAO.php");
				require("../UserControl/header.php");
			?>

			<div id="content">
				<div id="shop-banner">
					<img src="../temp/shop-banner.jpg" />
				</div>
				<?php
					require("../UserControl_NguoiBan/MenuDanhMucChucNang.php");
				?>
				<div id="seller-shop-info" class="block layout-2col-col2">
					<div class="title">
					  <h3>Đăng Sản Phẩm Mới</h3>
				  </div>
					<div id="detailcontent" class="content">
                    <ul id="nested-list">
                    <?php
			
						function HienDanhMucCon($dm_ma)
						{
							$listdanhmuc = DanhMucSanPham::DanhSachDanhMucCon($dm_ma);
							if(count($listdanhmuc) > 0)
							{
								echo "<ul>";
								foreach($listdanhmuc as $danhmuc)
								{
									$listdanhmuc = DanhMucSanPham::DanhSachDanhMucCon($danhmuc->dm_ma);
									if(count($listdanhmuc) > 0)
										echo "<li class='open'><span id='$danhmuc->dm_ma'>$danhmuc->dm_ten</span> <input type='button' id='add$danhmuc->dm_ma' class='add' onclick='Add($danhmuc->dm_ma)' /><input type='button' class='edit' onclick='Sua($danhmuc->dm_ma)' id='edit$danhmuc->dm_ma' /><input id='delete$danhmuc->dm_ma'  type='button' class='delete' onclick='Xoa($danhmuc->dm_ma)' />";
									else
										echo "<li><span id='$danhmuc->dm_ma'>$danhmuc->dm_ten</span> <input type='button' id='add$danhmuc->dm_ma' class='add'  onclick='Add($danhmuc->dm_ma)' /><input type='button' class='edit' onclick='Sua($danhmuc->dm_ma)' id='edit$danhmuc->dm_ma' /><input id='delete$danhmuc->dm_ma'  type='button' class='delete' onclick='Xoa($danhmuc->dm_ma)' />";
									HienDanhMucCon($danhmuc->dm_ma);
									echo "</li>";
								}
								echo "</ul>";
							}
							
						}
						$listdanhmuc = DanhMucSanPham::DanhSachDanhMucCha();
						foreach($listdanhmuc as $danhmuc)
						{
							$listdanhmuc = DanhMucSanPham::DanhSachDanhMucCon($danhmuc->dm_ma);
							if(count($listdanhmuc) > 0)
								echo "<li class='open'><span id='$danhmuc->dm_ma'>$danhmuc->dm_ten</span> <input type='button' id='add$danhmuc->dm_ma' class='add' onclick='Add($danhmuc->dm_ma)' /><input type='button' class='edit' onclick='Sua($danhmuc->dm_ma)' id='edit$danhmuc->dm_ma' /><input id='delete$danhmuc->dm_ma'  type='button' class='delete' onclick='Xoa($danhmuc->dm_ma)' />";
							else
								echo "<li><span id='$danhmuc->dm_ma'>$danhmuc->dm_ten</span> <input type='button' id='add$danhmuc->dm_ma' class='add' onclick='Add($danhmuc->dm_ma)' /><input type='button' class='edit' onclick='Sua($danhmuc->dm_ma)' id='edit$danhmuc->dm_ma' /><input id='delete$danhmuc->dm_ma'  type='button' class='delete'  onclick='Xoa($danhmuc->dm_ma)' />";
							HienDanhMucCon($danhmuc->dm_ma);
							echo "</li>";
						}
					?>
                    </ul>
					</div>
				</div>
			</div>
			<?php
				require("../UserControl/footer.php");
			?>
		</div>
	</body>
</html>
